/*
 * DoAnLyThuyet_JavaOutLookView.java
 */

package doanlythuyet_javaoutlook;

import BUS.MyMailBUS;
import DTO.MyMailDTO;
import doanlythuyet_javaoutlook.MyUserControl.JFrame_CauHinhProxy;
import doanlythuyet_javaoutlook.MyUserControl.JFrame_Contact;
import doanlythuyet_javaoutlook.MyUserControl.JPanel_XemMail;
import java.io.IOException;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;

import doanlythuyet_javaoutlook.MyUserControl.JFrame_GuiMail;
import doanlythuyet_javaoutlook.MyUserControl.JTreeFromXMLFile;
import doanlythuyet_javaoutlook.MyUserControl.PopupMenu_MouseListerner_MyBangDanhSachFile;
import java.io.File;
import java.util.ArrayList;
import java.util.Hashtable;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.internet.MimeMessage;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.MutableTreeNode;
import javax.swing.tree.TreePath;
import org.xml.sax.SAXException;

/**
 * The application's main frame.
 */
public class DoAnLyThuyet_JavaOutLookView extends FrameView {

    /**
     * @return the jTree_ThuMucTrenMay
     */
    public static JTreeFromXMLFile getJTree_ThuMucTrenMay() {
        return jTree_ThuMucTrenMay;
    }

    /**
     * @param aJTree_ThuMucTrenMay the jTree_ThuMucTrenMay to set
     */
    public static void setJTree_ThuMucTrenMay(JTreeFromXMLFile aJTree_ThuMucTrenMay) {
        jTree_ThuMucTrenMay = aJTree_ThuMucTrenMay;
    }
    //private CayDuyetFile cayDuyetFile;
    private String thuMucDuocChon = "";
    private JPanel_XemMail jPanel_XemMail = new JPanel_XemMail();
    private JTreeFromXMLFile jTree_ThuMucMail;
    private static JTreeFromXMLFile jTree_ThuMucTrenMay;

    private void jXuLy_KhiNguoiDungDoiThuMucDuyetMail(String str_fileduocchon) {
        try {
            //throw new UnsupportedOperationException("Not supported yet.");
            //JOptionPane.showMessageDialog(null, "hien thi cac mail trong thu muc: " + str_fileduocchon + " (file DoAnLyThuyet_JavaOutLookView.java dong 54)");
            MyMailBUS mailBUS = new MyMailBUS();
            Hashtable<String, String> cacDieuKien = new Hashtable<String, String>();
            cacDieuKien.put("DuongDanThuMuc", str_fileduocchon);
            ArrayList<MyMailDTO> cacMailDTO = mailBUS.layTatCaMailVoiDieuKien(str_fileduocchon, cacDieuKien);
            jScrollPane_Giua.setViewportView(jPanel_XemMail);
            jSplitPane_GiuaPhai.setDividerLocation(800);
            jPanel_XemMail.DuaDanhSachMailVaoBang(cacMailDTO);
            jPanel_XemMail.setToolTipText(thuMucDuocChon);
        } catch (SQLException ex) {
            Logger.getLogger(DoAnLyThuyet_JavaOutLookView.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(DoAnLyThuyet_JavaOutLookView.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    private void initMailsComponents(){
        String dataPath = DoAnLyThuyet_JavaOutLookApp.getCurdir() + "\\src";
        dataPath = new File(".").getAbsolutePath();
        String fileName = "\\Database\\XML_ThuMucMail.xml";
        jTree_ThuMucMail = new JTreeFromXMLFile(dataPath + fileName, true);
        jScrollPane_ThuMucMail.setViewportView(jTree_ThuMucMail);
        jTree_ThuMucMail.addEventListener_ClickChuotVaoCayDuyetFile(new EventListener_ClickChuotVaoCayDuyetFile() {

            public void Event_ClickChuotVaoCayDuyetFile_Occurred(String str_fileduocchon) {
                thuMucDuocChon = str_fileduocchon;
                jXuLy_KhiNguoiDungDoiThuMucDuyetMail(thuMucDuocChon);
            }
        });

        fileName = "\\Database\\XML_ThuMucNguoiDung.xml";
        setJTree_ThuMucTrenMay(new JTreeFromXMLFile(dataPath + fileName, false));
        jScrollPane_ThuMucTrenMay.setViewportView(getJTree_ThuMucTrenMay());
        getJTree_ThuMucTrenMay().addEventListener_ClickChuotVaoCayDuyetFile(new EventListener_ClickChuotVaoCayDuyetFile() {

            public void Event_ClickChuotVaoCayDuyetFile_Occurred(String str_fileduocchon) {
                thuMucDuocChon = str_fileduocchon;
                jXuLy_KhiNguoiDungDoiThuMucDuyetMail(thuMucDuocChon);
            }
        });

        JMenuItem menuItem = (JMenuItem) jPanel_XemMail.getPopupMenu().getComponent(0);
        PopupMenu_MouseListerner_MyBangDanhSachFile mouseListerner = (PopupMenu_MouseListerner_MyBangDanhSachFile) menuItem.getMouseListeners()[1];
        mouseListerner.addEventListener_ClickChuotVaoCayDuyetFile(new EventListener_ClickChuotVaoCayDuyetFile() {
            public void Event_ClickChuotVaoCayDuyetFile_Occurred(String str_fileduocchon) {
                //throw new UnsupportedOperationException("Not supported yet.");
                jXuLy_KhiNguoiDungDoiThuMucDuyetMail(thuMucDuocChon);
            }
        });
    }
    public DoAnLyThuyet_JavaOutLookView(SingleFrameApplication app) throws SAXException {
        super(app);
        String dataPath = new File(".").getAbsolutePath();
        String strFileName = dataPath + "\\Database\\XML_Proxy.xml";

        DoAnLyThuyet_JavaOutLookApp.LayProxytuXML(strFileName);
        initComponents();
        initMailsComponents();
        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
/*
        cayDuyetFile= new CayDuyetFile(jScrollPane_ThuMucMail);
        cayDuyetFile.addEventListener_ClickChuotVaoCayDuyetFile(new EventListener_ClickChuotVaoCayDuyetFile() {

            public void Event_ClickChuotVaoCayDuyetFile_Occurred(String str_fileduocchon) {
                //JOptionPane.showMessageDialog(null, str_fileduocchon);
            }
        });*/
        //jXuLy_KhiNguoiDungDoiThuMucDuyetMail("Mails\\Inbox\\");
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = DoAnLyThuyet_JavaOutLookApp.getApplication().getMainFrame();
            aboutBox = new DoAnLyThuyet_JavaOutLookAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        DoAnLyThuyet_JavaOutLookApp.getApplication().show(aboutBox);

        //initMyComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jPanel_Tren = new javax.swing.JPanel();
        jToolBar2 = new javax.swing.JToolBar();
        jButton_Tool_GetMail = new javax.swing.JButton();
        jButton_NewMail = new javax.swing.JButton();
        jButton_Find = new javax.swing.JButton();
        jSplitPane_TraiVaGiua = new javax.swing.JSplitPane();
        jSplitPane_GiuaPhai = new javax.swing.JSplitPane();
        jPanel_BenPhai = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jEditorPane1 = new javax.swing.JEditorPane();
        jScrollPane_Giua = new javax.swing.JScrollPane();
        jLabel1 = new javax.swing.JLabel();
        jPanel_BenTrai = new javax.swing.JPanel();
        jToolBar1 = new javax.swing.JToolBar();
        jButton_Contact = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jSplitPane_ThuMuc = new javax.swing.JSplitPane();
        jScrollPane_ThuMucMail = new javax.swing.JScrollPane();
        jScrollPane_ThuMucTrenMay = new javax.swing.JScrollPane();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        jMenu_New = new javax.swing.JMenu();
        jMenuItem_Mail = new javax.swing.JMenuItem();
        jMenuItem_Contact = new javax.swing.JMenuItem();
        jMenuItem_Task = new javax.swing.JMenuItem();
        jMenuItem_Folder = new javax.swing.JMenuItem();
        jMenu_Open = new javax.swing.JMenu();
        jMenuItem_SelectItems = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        jMenu_Folder = new javax.swing.JMenu();
        jMenuItem_NewFolder = new javax.swing.JMenuItem();
        jMenuItem_CopyFolder = new javax.swing.JMenuItem();
        jMenuItem_DeleteFolder = new javax.swing.JMenuItem();
        jMenuItem_RenameFolder = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JSeparator();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        jMenu_Edit = new javax.swing.JMenu();
        jMenuItem_Cut = new javax.swing.JMenuItem();
        jMenuItem_Copy = new javax.swing.JMenuItem();
        jMenuItem_Paste = new javax.swing.JMenuItem();
        jSeparator3 = new javax.swing.JSeparator();
        jMenuItem_SelectAll = new javax.swing.JMenuItem();
        jSeparator4 = new javax.swing.JSeparator();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenu_Tools = new javax.swing.JMenu();
        jMenuItem_Receive = new javax.swing.JMenuItem();
        jMenuItem_Find = new javax.swing.JMenuItem();
        jMenuItem_Addressbook = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();

        mainPanel.setName("mainPanel"); // NOI18N
        mainPanel.setLayout(new java.awt.BorderLayout());

        jPanel_Tren.setName("jPanel_Tren"); // NOI18N

        jToolBar2.setRollover(true);
        jToolBar2.setName("jToolBar2"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(doanlythuyet_javaoutlook.DoAnLyThuyet_JavaOutLookApp.class).getContext().getResourceMap(DoAnLyThuyet_JavaOutLookView.class);
        jButton_Tool_GetMail.setIcon(resourceMap.getIcon("jButton_Tool_GetMail.icon")); // NOI18N
        jButton_Tool_GetMail.setText(resourceMap.getString("jButton_Tool_GetMail.text")); // NOI18N
        jButton_Tool_GetMail.setFocusable(false);
        jButton_Tool_GetMail.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton_Tool_GetMail.setName("jButton_Tool_GetMail"); // NOI18N
        jButton_Tool_GetMail.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton_Tool_GetMail.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_Tool_GetMailActionPerformed(evt);
            }
        });
        jToolBar2.add(jButton_Tool_GetMail);

        jButton_NewMail.setIcon(resourceMap.getIcon("jButton_NewMail.icon")); // NOI18N
        jButton_NewMail.setText(resourceMap.getString("jButton_NewMail.text")); // NOI18N
        jButton_NewMail.setFocusable(false);
        jButton_NewMail.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton_NewMail.setName("jButton_NewMail"); // NOI18N
        jButton_NewMail.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton_NewMail.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_NewMailActionPerformed(evt);
            }
        });
        jToolBar2.add(jButton_NewMail);

        jButton_Find.setIcon(resourceMap.getIcon("jButton_Find.icon")); // NOI18N
        jButton_Find.setText(resourceMap.getString("jButton_Find.text")); // NOI18N
        jButton_Find.setFocusable(false);
        jButton_Find.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton_Find.setName("jButton_Find"); // NOI18N
        jButton_Find.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton_Find.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_FindActionPerformed(evt);
            }
        });
        jToolBar2.add(jButton_Find);

        javax.swing.GroupLayout jPanel_TrenLayout = new javax.swing.GroupLayout(jPanel_Tren);
        jPanel_Tren.setLayout(jPanel_TrenLayout);
        jPanel_TrenLayout.setHorizontalGroup(
            jPanel_TrenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel_TrenLayout.createSequentialGroup()
                .addComponent(jToolBar2, javax.swing.GroupLayout.PREFERRED_SIZE, 655, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(189, Short.MAX_VALUE))
        );
        jPanel_TrenLayout.setVerticalGroup(
            jPanel_TrenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel_TrenLayout.createSequentialGroup()
                .addContainerGap(41, Short.MAX_VALUE)
                .addComponent(jToolBar2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        mainPanel.add(jPanel_Tren, java.awt.BorderLayout.PAGE_START);

        jSplitPane_TraiVaGiua.setDividerLocation(200);
        jSplitPane_TraiVaGiua.setName("jSplitPane_TraiVaGiua"); // NOI18N

        jSplitPane_GiuaPhai.setDividerLocation(400);
        jSplitPane_GiuaPhai.setName("jSplitPane_GiuaPhai"); // NOI18N

        jPanel_BenPhai.setName("jPanel_BenPhai"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jEditorPane1.setContentType(resourceMap.getString("jEditorPane1.contentType")); // NOI18N
        jEditorPane1.setText(resourceMap.getString("jEditorPane1.text")); // NOI18N
        jEditorPane1.setName("jEditorPane1"); // NOI18N
        jScrollPane1.setViewportView(jEditorPane1);

        javax.swing.GroupLayout jPanel_BenPhaiLayout = new javax.swing.GroupLayout(jPanel_BenPhai);
        jPanel_BenPhai.setLayout(jPanel_BenPhaiLayout);
        jPanel_BenPhaiLayout.setHorizontalGroup(
            jPanel_BenPhaiLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE)
        );
        jPanel_BenPhaiLayout.setVerticalGroup(
            jPanel_BenPhaiLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 408, Short.MAX_VALUE)
        );

        jSplitPane_GiuaPhai.setRightComponent(jPanel_BenPhai);

        jScrollPane_Giua.setName("jScrollPane_Giua"); // NOI18N

        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N
        jScrollPane_Giua.setViewportView(jLabel1);

        jSplitPane_GiuaPhai.setLeftComponent(jScrollPane_Giua);

        jSplitPane_TraiVaGiua.setRightComponent(jSplitPane_GiuaPhai);

        jPanel_BenTrai.setName("jPanel_BenTrai"); // NOI18N

        jToolBar1.setRollover(true);
        jToolBar1.setName("jToolBar1"); // NOI18N

        jButton_Contact.setIcon(resourceMap.getIcon("jButton_Contact.icon")); // NOI18N
        jButton_Contact.setText(resourceMap.getString("jButton_Contact.text")); // NOI18N
        jButton_Contact.setFocusable(false);
        jButton_Contact.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton_Contact.setName("jButton_Contact"); // NOI18N
        jButton_Contact.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton_Contact.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_ContactActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton_Contact);

        jButton1.setIcon(resourceMap.getIcon("jButton1.icon")); // NOI18N
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setName("jButton1"); // NOI18N
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton1);

        jSplitPane_ThuMuc.setDividerLocation(150);
        jSplitPane_ThuMuc.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
        jSplitPane_ThuMuc.setName("jSplitPane_ThuMuc"); // NOI18N

        jScrollPane_ThuMucMail.setName("jScrollPane_ThuMucMail"); // NOI18N
        jSplitPane_ThuMuc.setTopComponent(jScrollPane_ThuMucMail);

        jScrollPane_ThuMucTrenMay.setName("jScrollPane_ThuMucTrenMay"); // NOI18N
        jSplitPane_ThuMuc.setRightComponent(jScrollPane_ThuMucTrenMay);

        javax.swing.GroupLayout jPanel_BenTraiLayout = new javax.swing.GroupLayout(jPanel_BenTrai);
        jPanel_BenTrai.setLayout(jPanel_BenTraiLayout);
        jPanel_BenTraiLayout.setHorizontalGroup(
            jPanel_BenTraiLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
            .addComponent(jSplitPane_ThuMuc, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
        );
        jPanel_BenTraiLayout.setVerticalGroup(
            jPanel_BenTraiLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel_BenTraiLayout.createSequentialGroup()
                .addComponent(jSplitPane_ThuMuc, javax.swing.GroupLayout.DEFAULT_SIZE, 356, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jSplitPane_TraiVaGiua.setLeftComponent(jPanel_BenTrai);

        mainPanel.add(jSplitPane_TraiVaGiua, java.awt.BorderLayout.CENTER);

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        jMenu_New.setText(resourceMap.getString("jMenu_New.text")); // NOI18N
        jMenu_New.setName("jMenu_New"); // NOI18N

        jMenuItem_Mail.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem_Mail.setText(resourceMap.getString("jMenuItem_Mail.text")); // NOI18N
        jMenuItem_Mail.setName("jMenuItem_Mail"); // NOI18N
        jMenu_New.add(jMenuItem_Mail);

        jMenuItem_Contact.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem_Contact.setText(resourceMap.getString("jMenuItem_Contact.text")); // NOI18N
        jMenuItem_Contact.setName("jMenuItem_Contact"); // NOI18N
        jMenu_New.add(jMenuItem_Contact);

        jMenuItem_Task.setText(resourceMap.getString("jMenuItem_Task.text")); // NOI18N
        jMenuItem_Task.setName("jMenuItem_Task"); // NOI18N
        jMenu_New.add(jMenuItem_Task);

        jMenuItem_Folder.setText(resourceMap.getString("jMenuItem_Folder.text")); // NOI18N
        jMenuItem_Folder.setName("jMenuItem_Folder"); // NOI18N
        jMenu_New.add(jMenuItem_Folder);

        fileMenu.add(jMenu_New);

        jMenu_Open.setText(resourceMap.getString("jMenu_Open.text")); // NOI18N
        jMenu_Open.setName("jMenu_Open"); // NOI18N

        jMenuItem_SelectItems.setText(resourceMap.getString("jMenuItem_SelectItems.text")); // NOI18N
        jMenuItem_SelectItems.setName("jMenuItem_SelectItems"); // NOI18N
        jMenu_Open.add(jMenuItem_SelectItems);

        fileMenu.add(jMenu_Open);

        jSeparator1.setName("jSeparator1"); // NOI18N
        fileMenu.add(jSeparator1);

        jMenu_Folder.setText(resourceMap.getString("jMenu_Folder.text")); // NOI18N
        jMenu_Folder.setName("jMenu_Folder"); // NOI18N

        jMenuItem_NewFolder.setText(resourceMap.getString("jMenuItem_NewFolder.text")); // NOI18N
        jMenuItem_NewFolder.setName("jMenuItem_NewFolder"); // NOI18N
        jMenu_Folder.add(jMenuItem_NewFolder);

        jMenuItem_CopyFolder.setText(resourceMap.getString("jMenuItem_CopyFolder.text")); // NOI18N
        jMenuItem_CopyFolder.setName("jMenuItem_CopyFolder"); // NOI18N
        jMenu_Folder.add(jMenuItem_CopyFolder);

        jMenuItem_DeleteFolder.setText(resourceMap.getString("jMenuItem_DeleteFolder.text")); // NOI18N
        jMenuItem_DeleteFolder.setName("jMenuItem_DeleteFolder"); // NOI18N
        jMenu_Folder.add(jMenuItem_DeleteFolder);

        jMenuItem_RenameFolder.setText(resourceMap.getString("jMenuItem_RenameFolder.text")); // NOI18N
        jMenuItem_RenameFolder.setName("jMenuItem_RenameFolder"); // NOI18N
        jMenu_Folder.add(jMenuItem_RenameFolder);

        fileMenu.add(jMenu_Folder);

        jSeparator2.setName("jSeparator2"); // NOI18N
        fileMenu.add(jSeparator2);

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(doanlythuyet_javaoutlook.DoAnLyThuyet_JavaOutLookApp.class).getContext().getActionMap(DoAnLyThuyet_JavaOutLookView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        jMenu_Edit.setText(resourceMap.getString("jMenu_Edit.text")); // NOI18N
        jMenu_Edit.setName("jMenu_Edit"); // NOI18N

        jMenuItem_Cut.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem_Cut.setText(resourceMap.getString("jMenuItem_Cut.text")); // NOI18N
        jMenuItem_Cut.setName("jMenuItem_Cut"); // NOI18N
        jMenu_Edit.add(jMenuItem_Cut);

        jMenuItem_Copy.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem_Copy.setText(resourceMap.getString("jMenuItem_Copy.text")); // NOI18N
        jMenuItem_Copy.setName("jMenuItem_Copy"); // NOI18N
        jMenu_Edit.add(jMenuItem_Copy);

        jMenuItem_Paste.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem_Paste.setText(resourceMap.getString("jMenuItem_Paste.text")); // NOI18N
        jMenuItem_Paste.setName("jMenuItem_Paste"); // NOI18N
        jMenu_Edit.add(jMenuItem_Paste);

        jSeparator3.setName("jSeparator3"); // NOI18N
        jMenu_Edit.add(jSeparator3);

        jMenuItem_SelectAll.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem_SelectAll.setText(resourceMap.getString("jMenuItem_SelectAll.text")); // NOI18N
        jMenuItem_SelectAll.setName("jMenuItem_SelectAll"); // NOI18N
        jMenu_Edit.add(jMenuItem_SelectAll);

        jSeparator4.setName("jSeparator4"); // NOI18N
        jMenu_Edit.add(jSeparator4);

        jMenuItem1.setText(resourceMap.getString("jMenuItem1.text")); // NOI18N
        jMenuItem1.setName("jMenuItem1"); // NOI18N
        jMenu_Edit.add(jMenuItem1);

        menuBar.add(jMenu_Edit);

        jMenu_Tools.setText(resourceMap.getString("jMenu_Tools.text")); // NOI18N
        jMenu_Tools.setName("jMenu_Tools"); // NOI18N

        jMenuItem_Receive.setText(resourceMap.getString("jMenuItem_Receive.text")); // NOI18N
        jMenuItem_Receive.setName("jMenuItem_Receive"); // NOI18N
        jMenu_Tools.add(jMenuItem_Receive);

        jMenuItem_Find.setText(resourceMap.getString("jMenuItem_Find.text")); // NOI18N
        jMenuItem_Find.setName("jMenuItem_Find"); // NOI18N
        jMenu_Tools.add(jMenuItem_Find);

        jMenuItem_Addressbook.setText(resourceMap.getString("jMenuItem_Addressbook.text")); // NOI18N
        jMenuItem_Addressbook.setName("jMenuItem_Addressbook"); // NOI18N
        jMenu_Tools.add(jMenuItem_Addressbook);

        menuBar.add(jMenu_Tools);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 844, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 674, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton_ContactActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_ContactActionPerformed
        try {
            // TODO add your handling code here:
            JFrame_Contact contact = new JFrame_Contact();
            contact.setVisible(true);
        } catch (IOException ex) {
            Logger.getLogger(DoAnLyThuyet_JavaOutLookView.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(DoAnLyThuyet_JavaOutLookView.class.getName()).log(Level.SEVERE, null, ex);
        }

}//GEN-LAST:event_jButton_ContactActionPerformed
/**
 * lay cac mail moi 
 * @return
 * @throws java.lang.Exception
 */
    private int thucHienLayMailMoi () throws Exception{
        int Kq = 0;
        MyMail myMail = new MyMail(DoAnLyThuyet_JavaOutLookApp.getSmtp_host(), DoAnLyThuyet_JavaOutLookApp.getPop3_host(), DoAnLyThuyet_JavaOutLookApp.getUser()
                , DoAnLyThuyet_JavaOutLookApp.getPass(), DoAnLyThuyet_JavaOutLookApp.getProxy(), DoAnLyThuyet_JavaOutLookApp.getPort());
        Session session = myMail.getMailSession(true);
        Message mess[] = myMail.layCacMessageTrongInbox(session);
        DefaultTreeModel model = (DefaultTreeModel) jTree_ThuMucMail.getJTreeThuMucNguoiDung().getModel();

        //TreePath treePath = jTree_ThuMucMail.getJTreeThuMucNguoiDung().getPathForRow(0).g
        MutableTreeNode treeNode = (MutableTreeNode) model.getRoot();
        TreePath treePath = new TreePath(treeNode);
        treePath = treePath.pathByAddingChild(treeNode.getChildAt(0));
        Kq = mess.length;
        //model.valueForPathChanged(treePath, "<html><head></head><body><b style=\"color:red\">" +
        //        "Inbox (" + Kq + " new)" +
         //       "</b></body></html>");
        jTree_ThuMucMail.getJTreeThuMucNguoiDung().setModel(model);

        for (Message message: mess){
            int idMail = JFrame_GuiMail.luuMailVaoCSDL((MimeMessage)message,"Mails\\Inbox\\");
            JFrame_GuiMail.luuAttachVaoCSDL((MimeMessage)message, idMail);
        }
        return Kq;
    }

    private void jButton_Tool_GetMailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_Tool_GetMailActionPerformed
        try {
            // TODO add your handling code here:
            int soMailMoi = thucHienLayMailMoi();
            int conf = JOptionPane.showConfirmDialog(null, "Co " + soMailMoi + " thu moi! Ban co muon mo thu muc inbox ngay khong?",
                    "Thong bao lay mail thanh cong!", JOptionPane.OK_OPTION);
            if (conf == JOptionPane.OK_OPTION){
                jPanel_XemMail.setToolTipText("Mails\\Inbox\\");
                jXuLy_KhiNguoiDungDoiThuMucDuyetMail("Mails\\Inbox\\");
            }

        } catch (Exception ex) {
            Logger.getLogger(DoAnLyThuyet_JavaOutLookView.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton_Tool_GetMailActionPerformed

    private void jButton_FindActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_FindActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton_FindActionPerformed

    private void jButton_NewMailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_NewMailActionPerformed
        // TODO add your handling code here:
         JFrame_GuiMail jFrame_GuiMail = new JFrame_GuiMail();
         jFrame_GuiMail.show();
    }//GEN-LAST:event_jButton_NewMailActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        JFrame_CauHinhProxy jFrame_cauhinh = new JFrame_CauHinhProxy();
        jFrame_cauhinh.show();
    }//GEN-LAST:event_jButton1ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton_Contact;
    private javax.swing.JButton jButton_Find;
    private javax.swing.JButton jButton_NewMail;
    private javax.swing.JButton jButton_Tool_GetMail;
    private javax.swing.JEditorPane jEditorPane1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem_Addressbook;
    private javax.swing.JMenuItem jMenuItem_Contact;
    private javax.swing.JMenuItem jMenuItem_Copy;
    private javax.swing.JMenuItem jMenuItem_CopyFolder;
    private javax.swing.JMenuItem jMenuItem_Cut;
    private javax.swing.JMenuItem jMenuItem_DeleteFolder;
    private javax.swing.JMenuItem jMenuItem_Find;
    private javax.swing.JMenuItem jMenuItem_Folder;
    private javax.swing.JMenuItem jMenuItem_Mail;
    private javax.swing.JMenuItem jMenuItem_NewFolder;
    private javax.swing.JMenuItem jMenuItem_Paste;
    private javax.swing.JMenuItem jMenuItem_Receive;
    private javax.swing.JMenuItem jMenuItem_RenameFolder;
    private javax.swing.JMenuItem jMenuItem_SelectAll;
    private javax.swing.JMenuItem jMenuItem_SelectItems;
    private javax.swing.JMenuItem jMenuItem_Task;
    private javax.swing.JMenu jMenu_Edit;
    private javax.swing.JMenu jMenu_Folder;
    private javax.swing.JMenu jMenu_New;
    private javax.swing.JMenu jMenu_Open;
    private javax.swing.JMenu jMenu_Tools;
    private javax.swing.JPanel jPanel_BenPhai;
    private javax.swing.JPanel jPanel_BenTrai;
    private javax.swing.JPanel jPanel_Tren;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane_Giua;
    private javax.swing.JScrollPane jScrollPane_ThuMucMail;
    private javax.swing.JScrollPane jScrollPane_ThuMucTrenMay;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JSplitPane jSplitPane_GiuaPhai;
    private javax.swing.JSplitPane jSplitPane_ThuMuc;
    private javax.swing.JSplitPane jSplitPane_TraiVaGiua;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JToolBar jToolBar2;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    // End of variables declaration//GEN-END:variables

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;

    private JDialog aboutBox;
}
